<?php
// +----------------------------------------------------------------------
// | WoShiMaiJia Projcet 
// +----------------------------------------------------------------------
// | Copyright (c) 2010-2011 http://woshimaijia.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: xinqiyang <xinqiyang@gmail.com>
// +----------------------------------------------------------------------

/**
 * POST Logic 
 * NEED TO ADD CACHE LAYER
 * @author xinqiyang
 *
 */
class PostLogic extends BaseService
{
	
	public static  function addPost($array)
	{
		return self::add('post', $array);
	}
	
	
	public static function getByObject($object,$topic_id='',$offset=0,$number=40)
	{
		//DO CACHE LAYER
		$where = $topic_id ? "object ='{$object}' and status=0 and topic_id={$topic_id} order by istopic desc,istop desc,id desc limit {$offset},{$number}" : "object ='{$object}' and status=0  order by id desc limit {$offset},{$number}";
		return self::gets('post',$where);
	}
	
	/**
	 * get post by userid
	 * 
	 * @param bigint $user_id
	 * @param int $limit
	 */
	public static function getPostByUserid($user_id,$limit)
	{
		$where = "user_id=$user_id and status=0 limit 10";
		return self::gets('post', $where);
	}
	
	/**
	 * id arrays
	 * @param array $array array(''=>'')
	 */
	public static function destoryPost($array)
	{
		return self::destory('post', $array);
	}
}